package com.fruit.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Description: 接收mq消息
 * @Author: LJ
 * @Date: 2018/11/2 15:35
 * @version:
 */
@Slf4j
@Component
public class MqReceiver {
    /**
     *
     * @param message
     */
    //第一种手动创建队列
    //@RabbitListener(queues = "myQueue")
    //第二种自动创建队列
    //@RabbitListener(queuesToDeclare = @Queue("myQueue"))
    //第三种 自动创建队列并且绑定exchanges
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange = @Exchange("myExchage")
    ))
    public void  process(String message){

        log.info("MqReceiver:{}" , message);
    }
    /**
     *  第一种服务商接收消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "computer",
            value = @Queue("computerOrder")
    ))
    public void  processComputer(String message){

        log.info("computer MqReceiver:{}" , message);
    }
    /**
     *  第二种服务商接收消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "fruit",
            value = @Queue("fruitOrder")
    ))
    public void  processFruit(String message){

        log.info("fruit MqReceiver:{}" , message);
    }
}
